package com.lagou.edu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author czq
 * @date 2020/7/15 21:52
 */
@Controller
@RequestMapping("/login")
public class LoginController {

    private final String ADMIN = "admin";

    @RequestMapping("/index")
    public String index() {
        return "login";
    }

    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response, String username, String password) throws IOException {

        if (username == null || password == null) {
            return "login";
        }

        if (ADMIN.equals(username) && ADMIN.equals(password)) {
            // 登录成功则把登录信息存储到 session 中
            request.getSession().setAttribute("username", ADMIN);
            response.sendRedirect("/resume/findAll");
            return "success";
        } else {
            return "login";
        }
    }
}
